<html>
<head><meta charset="utf-8"><title>Handling Pattern span better · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html">Handling Pattern span better</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213963187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213963187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213963187">(Oct 20 2020 at 18:48)</a>:</h4>
<p>So last couple meetings I had mentioned that we there was a change that recently pushed to master to handle spans around Pattern expressionsin a better way.  PR that added this is <a href="https://github.com/rust-lang/rust/pull/75933/files#diff-1f18144176a6e44f905262991bed987098348cdbd688ac76f8c915ec91b7fd58R316-R319">here</a></p>
<p>But the main idea behind this is that in the case of Patterns we rely on the upvars_mentioned span instead of the span of the pattern itself. This works today because entities in upvars_mentioned are the same as those in closure_captures.</p>
<p>However, this won't help us with precise capture. </p>
<p>The main reason behind this is the Place that we look at for capturing the precise is the pattern part and not the discriminant for the pattern match. (rightly so)</p>



<a name="213963642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213963642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213963642">(Oct 20 2020 at 18:51)</a>:</h4>
<p>If we look at the pattern expression the output as expected would look like (<a href="https://github.com/sexxi-goose/rust/commit/08f33f2cedf6d1a20cd5c020acfdf34ea0c98969">https://github.com/sexxi-goose/rust/commit/08f33f2cedf6d1a20cd5c020acfdf34ea0c98969</a>)</p>
<p>We have a hack kind of around it, but it creates incorrect associations. When we call consume for a pattern in ExprUseVisitor we modify the PlaceWithHirId to point to the disciminant and not the pattern. </p>
<p><a href="https://github.com/sexxi-goose/rust/commit/dafa9d16d8cbc19e0c5ac4d656c146e58ba1c5cc">https://github.com/sexxi-goose/rust/commit/dafa9d16d8cbc19e0c5ac4d656c146e58ba1c5cc</a></p>



<a name="213964063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964063">(Oct 20 2020 at 18:54)</a>:</h4>
<p>IMO the proper way would be to probably introduce a notion of patterns in the ExperUseVisitor Delegate, but not sure if we want that either.</p>



<a name="213964124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964124">(Oct 20 2020 at 18:55)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="213964774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964774">(Oct 20 2020 at 19:00)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> I'm having a bit of trouble following this</p>



<a name="213964850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964850">(Oct 20 2020 at 19:01)</a>:</h4>
<p>the problem is that the span of the "move" comes from the binding in the pattern</p>



<a name="213964859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964859">(Oct 20 2020 at 19:01)</a>:</h4>
<p>and not the expression that is being moved out of?</p>



<a name="213964910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964910">(Oct 20 2020 at 19:01)</a>:</h4>
<p>so e.g. <code>let p = y</code> would wind up with a span of <code>p</code>, but we would prefer the span to be <code>y</code>?</p>



<a name="213964965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213964965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213964965">(Oct 20 2020 at 19:01)</a>:</h4>
<p>and yet it can also happen that you have <code>let (p, ..) = x</code> which would move just <code>x.0</code></p>



<a name="213965095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965095">(Oct 20 2020 at 19:02)</a>:</h4>
<p>That's fair actually</p>



<a name="213965137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965137">(Oct 20 2020 at 19:03)</a>:</h4>
<p>Actually I guess it makes sense today, because the struct is captured in its entirety</p>



<a name="213965233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965233">(Oct 20 2020 at 19:03)</a>:</h4>
<p>Well, I think that underlining the pattern binding makes "sense" but <em>is</em> confusing</p>



<a name="213965251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965251">(Oct 20 2020 at 19:03)</a>:</h4>
<p>especially in the common case of <code>let y = x</code></p>



<a name="213965306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965306">(Oct 20 2020 at 19:04)</a>:</h4>
<p>(I guess I'm not entirely sure how common that case is)</p>



<a name="213965334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965334">(Oct 20 2020 at 19:04)</a>:</h4>
<p>it does seem to me that underlining the expression being matched might be clearer</p>



<a name="213965387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965387">(Oct 20 2020 at 19:04)</a>:</h4>
<p>Yeah</p>



<a name="213965716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965716">(Oct 20 2020 at 19:07)</a>:</h4>
<p>This code is also part of handling match arms, so those will be affected too</p>



<a name="213965757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213965757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213965757">(Oct 20 2020 at 19:07)</a>:</h4>
<p>Actually nvm, those don't create bindings, so that will be fine</p>



<a name="213966200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966200">(Oct 20 2020 at 19:10)</a>:</h4>
<p>I guess <span class="user-mention" data-user-id="281950">@Aman Arora</span> I'd have to dig a bit into the code, is the problem that the<code>ExprUseVisitor</code> isn't passing down a kind of "separate span" here?</p>



<a name="213966219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966219">(Oct 20 2020 at 19:10)</a>:</h4>
<p>but just giving a <code>PlaceWithHirId</code> that identifies the pattern?</p>



<a name="213966307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966307">(Oct 20 2020 at 19:11)</a>:</h4>
<p>gimme a min, lemme point to it</p>



<a name="213966501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966501">(Oct 20 2020 at 19:12)</a>:</h4>
<p><a href="https://github.com/sexxi-goose/rust/blob/use_places_new/compiler/rustc_typeck/src/expr_use_visitor.rs#L506">https://github.com/sexxi-goose/rust/blob/use_places_new/compiler/rustc_typeck/src/expr_use_visitor.rs#L506</a></p>



<a name="213966562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966562">(Oct 20 2020 at 19:13)</a>:</h4>
<p>So the discr_place is the one that's on RHS</p>



<a name="213966713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966713">(Oct 20 2020 at 19:14)</a>:</h4>
<p>we essentially pass that to mem_cat to apply projections as required based on the pattern,  when mem_cat applies the projections it changes the expression pointed to within the PlaceWithHirId  to be that of the pattern so the arm/destruct pattern etc</p>



<a name="213966817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213966817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213966817">(Oct 20 2020 at 19:15)</a>:</h4>
<p>Only in case of a match block do we actually call the delgate on that place </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">            </span><span class="n">hir</span>::<span class="n">ExprKind</span>::<span class="n">Match</span><span class="p">(</span><span class="k">ref</span><span class="w"> </span><span class="n">discr</span><span class="p">,</span><span class="w"> </span><span class="n">arms</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="kd">let</span><span class="w"> </span><span class="n">discr_place</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">return_if_err</span><span class="o">!</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">mc</span><span class="p">.</span><span class="n">cat_expr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">discr</span><span class="p">));</span><span class="w"></span>
<span class="w">                </span><span class="bp">self</span><span class="p">.</span><span class="n">borrow_expr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">discr</span><span class="p">,</span><span class="w"> </span><span class="n">ty</span>::<span class="n">ImmBorrow</span><span class="p">);</span><span class="w"></span>

<span class="w">                </span><span class="c1">// treatment of the discriminant is handled while walking the arms.</span>
<span class="w">                </span><span class="k">for</span><span class="w"> </span><span class="n">arm</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">arms</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="bp">self</span><span class="p">.</span><span class="n">walk_arm</span><span class="p">(</span><span class="o">&amp;</span><span class="n">discr_place</span><span class="p">,</span><span class="w"> </span><span class="n">arm</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>(walk_arm calls walk_pat)</p>



<a name="213971461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971461">(Oct 20 2020 at 19:56)</a>:</h4>
<p>yeah</p>



<a name="213971515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971515">(Oct 20 2020 at 19:56)</a>:</h4>
<p>so we could modify the <code>Delegate</code> interface</p>



<a name="213971537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971537">(Oct 20 2020 at 19:56)</a>:</h4>
<p>so that it can take an optional "extra" span</p>



<a name="213971543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971543">(Oct 20 2020 at 19:57)</a>:</h4>
<p>or has extra methods</p>



<a name="213971561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971561">(Oct 20 2020 at 19:57)</a>:</h4>
<p>e.g., <code>consume_pattern(place, span)</code></p>



<a name="213971584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971584">(Oct 20 2020 at 19:57)</a>:</h4>
<p>and then we could thread down the span of the <code>discr</code></p>



<a name="213971600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971600">(Oct 20 2020 at 19:57)</a>:</h4>
<p>match is an interesting one too</p>



<a name="213971675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971675">(Oct 20 2020 at 19:58)</a>:</h4>
<p>I'll make that an expr_id, because that makes it easy to integrate it with the Capture information structure</p>



<a name="213971685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971685">(Oct 20 2020 at 19:58)</a>:</h4>
<p>e.g., if you have <code>match x { (_, b) =&gt; </code>, what do we want underlined :)</p>



<a name="213971719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971719">(Oct 20 2020 at 19:58)</a>:</h4>
<p>Right now it will do x, because that's how things are setup</p>



<a name="213971789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971789">(Oct 20 2020 at 19:59)</a>:</h4>
<p>Actually no, today it will point to the first/last use of x in the closure, AFAIK, unless x is moved</p>



<a name="213971845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213971845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213971845">(Oct 20 2020 at 19:59)</a>:</h4>
<p>since for ByRef Capture we look at upvars_mentioned</p>



<a name="213972052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972052">(Oct 20 2020 at 20:01)</a>:</h4>
<p>if you can modify the interface so that it <em>always</em> takes a place and an expr-id</p>



<a name="213972061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972061">(Oct 20 2020 at 20:01)</a>:</h4>
<p>and sometimes they have the same hir-id</p>



<a name="213972063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972063">(Oct 20 2020 at 20:01)</a>:</h4>
<p>and sometimes they don't</p>



<a name="213972070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972070">(Oct 20 2020 at 20:01)</a>:</h4>
<p>that might be the most elegant</p>



<a name="213972102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972102">(Oct 20 2020 at 20:01)</a>:</h4>
<p>i.e., for patterns they do not</p>



<a name="213972109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972109">(Oct 20 2020 at 20:01)</a>:</h4>
<p>but for expressions they would</p>



<a name="213972130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972130">(Oct 20 2020 at 20:01)</a>:</h4>
<p>it'd be nice if the code didn't have a lot of ifs, is what i'm getting at</p>



<a name="213972166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972166">(Oct 20 2020 at 20:02)</a>:</h4>
<p>I think that can work. I think this should be done before the capture analysis PR since the interface change would affect clippy</p>



<a name="213972222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972222">(Oct 20 2020 at 20:02)</a>:</h4>
<p>but instead it was like "here is the <code>HirId</code> of the thing that ought to be reported to the user as the use"</p>



<a name="213972629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213972629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213972629">(Oct 20 2020 at 20:05)</a>:</h4>
<p>Sounds good</p>



<a name="213978176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213978176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213978176">(Oct 20 2020 at 20:54)</a>:</h4>
<p>cc: <span class="user-mention" data-user-id="282558">@Dhruv Jauhar</span></p>



<a name="213991057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/213991057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#213991057">(Oct 20 2020 at 23:17)</a>:</h4>
<p><a href="https://github.com/rust-lang/project-rfc-2229/issues/20">https://github.com/rust-lang/project-rfc-2229/issues/20</a></p>



<a name="215287712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/215287712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#215287712">(Nov 02 2020 at 07:59)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/78662">https://github.com/rust-lang/rust/pull/78662</a> is up</p>



<a name="215318146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/215318146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#215318146">(Nov 02 2020 at 13:32)</a>:</h4>
<p>left a few wording nits but looks good</p>



<a name="215562588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Handling%20Pattern%20span%20better/near/215562588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Handling.20Pattern.20span.20better.html#215562588">(Nov 04 2020 at 10:19)</a>:</h4>
<p>Dhruv pushed a fixup <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>